<template>
  <div class="login-container">
    <div class="login-box">
      <h2>物联网登录</h2>
      <form @submit.prevent="login">
        <div class="form-group">
          <label for="username">账号</label>
          <input
            type="text"
            id="username"
            v-model="username"
            placeholder="请输入账号"
            required
          />
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input
            type="password"
            id="password"
            v-model="password"
            placeholder="请输入密码"
            required
          />
        </div>
        <button type="submit">登录</button>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'loginPage',
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    login() {
      // 这里可以添加登录逻辑，比如调用API验证账号密码
      if (this.username && this.password) {
        // alert(`登录成功！账号: ${this.username}`);
        this.$router.push('/layout');
        // 这里可以跳转到其他页面
      } else {
        alert('请输入账号和密码');
      }
    },
  },
};
</script>

<style>
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, sans-serif;
}

.login-container {
  background: url("../static/bg.jpg");
  background-size: cover;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: 100vh;
  background-color: #f0f2f5;
  padding-right: 10%;
}

.login-box {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  width: 400px;
}

h2 {
  text-align: center;
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

input {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}
</style>